

libname ra "E:\data";/*cohort*/
libname pd "Z:\Medicare_20\Part_D";/*input part D*/
libname pb "Z:\Medicare_20\Part_b";/*input carrier*/
libname medpar "Z:\Medicare_20\MedPAR";/*input ip dataset*/
libname op "Z:\Medicare_20\OP";/*input op dataset*/
libname mbsf "Z:\Medicare_20\mbsf";/*input demo dataset*/


**********Purpose: Run Cox models with comorbidity as time-varying covariate and as a baseline covariate************;
/***Note:
       - ra.cox1 dataset cotains the analytical cohort with baseline variables plus comorbidity 
          (elix-hauser score) as time varying variable.
            -Elix-hauser score as time-varying variable was created by pulling comorbidity claims 
              using ICD codes from ip,op and part b files between index and stop date.
             -It is a multiple row per id, with each row representing accrual of comorbidities
              *first row of this data represents baseline values**********/

**********************COMORBIDITY AS TIME_VARYING COV**************************;

**************************unadjusted models*************************************************;

****comorb***;
proc phreg data=ra.cox1;
model (from_index, next_time)*event(0) = ELX_SCORE1 / ties=exact risklimits;
run;

*****age*****;
proc phreg data=ra.cox1;
model (from_index, next_time)*event(0) =  age_index2 / ties=exact risklimits;
run;

****sex*******;
proc phreg data=ra.cox1;
class   BENE_SEX_IDENT_CD (ref= "1");
model (from_index, next_time)*event(0) = BENE_SEX_IDENT_CD/ ties=exact risklimits;
run;

******race****;
proc phreg data=ra.cox1;
class  race(ref="1") ;
model (from_index, next_time)*event(0) =  race / ties=exact risklimits;
run;

*****LIS***;
proc phreg data=ra.cox1;
class  lis_pre_bin(ref="0") ;
model (from_index, next_time)*event(0) =  lis_pre_bin / ties=exact risklimits;
run;

****************************fully adjusted model***********************************************;
proc phreg data=ra.cox1;
  class  race(ref="1") lis_pre_bin (ref="0") BENE_SEX_IDENT_CD (ref= "1");
  model (from_index, next_time)*event(0) = ELX_SCORE1 age_index2 race lis_pre_bin
  BENE_SEX_IDENT_CD/  ties=exact risklimits;
run;


*****************************MODELS WITH BASELINE COVARIATES INCLUDING COMORB****************************;

******************unadjusted*********;
****age*****;
proc phreg data=ra.cox1;
model fu *desc01(0) =  age_index2 /  ties=exact risklimits;
where from_index=0;/*keep bl row*/
run;

***gender****;
proc phreg data=ra.cox1;
class   BENE_SEX_IDENT_CD (ref= "1");
model fu *desc01(0) = 
BENE_SEX_IDENT_CD/  ties=exact risklimits;
where from_index=0;
run;

******race****;
proc phreg data=ra.cox1;
class  race(ref="1") ;
model fu *desc01(0) =  race /  ties=exact risklimits;
where from_index=0;
run;

*****lis*****;
proc phreg data=ra.cox1;
class   lis_pre_bin (ref="0") ;
model fu *desc01(0) =  lis_pre_bin/  ties=exact risklimits;
where from_index=0;
run;

************comorb*********;
proc phreg data=ra.cox1;
model fu *desc01(0) = ELX_SCORE1 /  ties=exact risklimits;
where from_index=0;
run;


****************fully adjusted model***************************;
proc phreg data=ra.cox1;
class  race(ref="1") lis_pre_bin (ref="0") BENE_SEX_IDENT_CD (ref= "1");
model fu *desc01(0) = ELX_SCORE1 age_index2 race lis_pre_bin
BENE_SEX_IDENT_CD/  ties=exact risklimits;
where from_index=0;/*bl row*/
run;























*




